package com.woniuxy.woniubookmanager.intercepters;

import com.woniuxy.woniubookmanager.utils.JwtUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@Component
public class PermnissionIntercepter implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        //登录之后
        if (token != null) {
            //解析token
           // JwtUtils.parseToken()
            return true ;
        }

        //没有登录
        if (token == null){
            PrintWriter writer = response.getWriter();
            writer.print("noLogin");
            writer.close();
        }
        return false ;
    }
}
